package com.test.languagetest;

import org.hibernate.SessionFactory;
import org.hibernate.cfg.Configuration;
import org.hibernate.classic.Session;

import com.pojo.Product;

public class HibernateTestSaveOne {

	public static void main(String[] args) {
		// 获取SessionFactory
		SessionFactory sf = new Configuration().configure().buildSessionFactory();
		// 从SessionFactory中获取session
		Session s = sf.openSession();
		// 开启事务，一个线程一个事务
		s.beginTransaction();
		// 调用session的save方法保存对象
		Product p = new Product();
		p.setName("iphone7");
		p.setPrice(5000);
		s.save(p);
		// 提交事务
		s.getTransaction().commit();
		// 关闭session
		s.close();
		// 关闭SessionFactory
		sf.close();
	}
}
